/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Army;

import java.awt.Graphics2D;

/**
 *
 * @author Huy
 */
public abstract class Bullet extends ArmyEntity {

	double speed;
	double range;
	int damage;
	float movedDistant = 0;
	int liveTime;
	boolean isHited = false;

	public Bullet() {
	}

	public int getDamage() {
		return damage;
	}

	public boolean isIsHited() {
		return isHited;
	}

	public float getMovedDistant() {
		return movedDistant;
	}

	public double  getRange() {
		return range;
	}

	public double getSpeed() {
		return speed;
	}

	@Override
	public void update() {
		super.update();
		if (isHited) {
			liveTime--;
			if (liveTime < 0) {
				isDetroyed = true;
			}
			return;
		}
		int y = -(int) (speed * Math.cos(sprite.getRotation()));
		int x = (int) (speed * Math.sin(sprite.getRotation()));
		movedDistant += Math.sqrt(x * x + y * y);
		sprite.move(x, y);
		if (movedDistant > range) {
			isHited = true;
		}
	}

	@Override
	public void draw(Graphics2D g) {
		sprite.draw(g);
	}
}
